import viewmodeEnum from "../enum/viewmode.enum"
import Data from "../object/Data"

export default class CameraStartData extends Data {
  pose: CameraStartPose
  icon: string
  thumb: any
  modified: Date

  constructor(icon?: string, thumb?: any, i?) {
    super()
    this.name = "cam-start"
    this.icon = icon
    this.thumb = thumb
    this.modified = new Date(0)
    this.pose = new CameraStartPose()
    i && this.pose.copy(i)
  }
  copy(e: CameraStartData) {
    this.icon = e.icon
    this.thumb = e.thumb
    this.modified = e.modified || new Date()
    this.pose.copy(e.pose)
    return this
  }
  get hasCameraPose() {
    return this.pose && this.pose.camera && this.pose.camera.position
  }
}
export class CameraStartPose {
  pano: any
  mode: number
  floorVisibility: any
  camera: { position: THREE.Vector3; rotation: THREE.Vector3; zoom: number }
  constructor(mode = viewmodeEnum.Panorama, position?: THREE.Vector3, rotation?: THREE.Vector3, zoom?: number, pano?: any, floorVisibility?) {
    this.mode = mode
    this.camera = {
      position: position || null,
      rotation: rotation || null,
      zoom: zoom || null
    }
    this.pano = pano || { uuid: null }
    this.floorVisibility = floorVisibility || null
  }
  copy(e: Partial<CameraStartPose>) {
    this.camera.position = copyData(e.camera.position, this.camera.position)
    this.camera.rotation = copyData(e.camera.rotation, this.camera.rotation)
    this.camera.zoom = e.camera.zoom
    this.pano.uuid = e.pano.uuid ? e.pano.uuid.slice() : void 0
    this.mode = e.mode
    this.floorVisibility = e.floorVisibility ? e.floorVisibility.slice() : void 0
    return this
  }
}
const copyData = (e: THREE.Vector3, t: THREE.Vector3) => (e && t ? t.copy(e) : e && !t ? e.clone() : void 0)
